package com.david.warehouse.service.impl;

import com.david.warehouse.mapper.ProductMapper;
import com.david.warehouse.pojo.entity.Product;
import com.david.warehouse.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;


    @Override
    public String addProduct(Product product) {
        if (Objects.isNull(product.getId())){
            productMapper.insertProduct(product);
            return "添加成功";
        } else {
            productMapper.updateProduct(product);
            return "修改成功";
        }
    }

    @Override
    public List<Product> getProductList(String categoryId, String typeId) {
        return productMapper.selectProductList(categoryId,typeId);
    }

    @Override
    public void deleteProductById(Integer id) {
        productMapper.deleteProductById(id);
    }
}
